package y23.Dec;

public class Test12 {
    static class ListNode{
        public int val;//节点的值域
        public ListNode next;//下一个节点的地址
        public ListNode(int val){
            this.val = val;
        }
    }
    public ListNode head;//当前链表的头节点
    public void addFirst(int data){
        ListNode node = new ListNode(data);
        node.next = head;
        head = node;
    }
    public void display(){
        ListNode cur = head;
        while (cur != null){
            System.out.print(cur.val + " ");
            cur = cur.next;
        }
    }
    public void reverseBetween(int left, int right) {

    }
    public void deleteDuplicates(ListNode head) {
        if(head == null || head.next == null){
            return;
        }
        ListNode cur = head;
        while(cur.next != null){
            delete(cur);
            cur = cur.next;
        }
    }
    public void delete(ListNode head){
        ListNode pro = head;
        ListNode end = head.next;
        while(end != null){
            if(end.val == head.val){
                pro.next = end.next;
                end = end.next;
            }else {
                pro = pro.next;
                end = end.next;
            }

        }
    }

    public static void main(String[] args) {
        Test12 test = new Test12();
        test.addFirst(2);
        test.addFirst(1);
        test.addFirst(1);
        test.deleteDuplicates(test.head);
        test.display();
    }
}
